<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="名称" prop="name">
        <el-input v-model="queryParams.name" placeholder="请输入名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd" v-hasPermi="['train:FileFolder:edit']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate" v-hasPermi="['train:FileFolder:edit']">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete" v-hasPermi="['train:FileFolder:edit']">删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport" >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table border v-loading="loading" :data="FileFolderList" @selection-change="handleSelectionChange">
      <el-table-column resizable show-overflow-tooltip type="selection" width="55" align="center" />
      <el-table-column resizable show-overflow-tooltip label="名称" align="center" prop="name" />
      <el-table-column resizable show-overflow-tooltip label="备注" align="center" prop="remark" />
      <el-table-column resizable label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" @click="showFileInfo(scope.row)">文件信息</el-button>
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)" v-hasPermi="['train:FileFolder:edit']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="['train:FileFolder:edit']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改资源文件夹对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1000px" append-to-body>
      <el-row>
        <el-form ref="form" :model="form" :rules="rules" label-width="80px">

          <el-col :span="12">
            <el-form-item label="名称" prop="name">
              <el-input v-model="form.name" placeholder="请输入名称" style="width: 320px" clearale />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="备注" prop="remark">
              <el-input v-model="form.remark" placeholder="请输入备注" style="width: 320px" clearale />
            </el-form-item>
          </el-col>
        </el-form>
      </el-row>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 文件信息展示 -->
    <el-dialog :title="fileTitle" :visible.sync="fileOpen" width="1000px" append-to-body>
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
        <el-form-item label="名称" prop="fileName">
          <el-input v-model="fileInfoQueryParams.fileName" placeholder="请输入名称" clearable
            @keyup.enter.native="fileInfoHandleQuery" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="fileInfoHandleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="fileInfoResetQuery">重置</el-button>
        </el-form-item>
        <el-form-item>
          <el-upload :show-file-list="false" ref="upload" action="#" :http-request="uploadFile">
            <el-button type="primary" size="mini" v-hasPermi="['train:FileFolder:edit']">上传文件</el-button>
          </el-upload>
        </el-form-item>
      </el-form>
      <el-table border v-loading="loading" :data="fileInfoList" @selection-change="handleSelectionChangeFile">
        <el-table-column resizable show-overflow-tooltip type="selection" width="55" align="center" />
        <el-table-column resizable show-overflow-tooltip label="名称" align="center" prop="fileName" />
        <el-table-column resizable show-overflow-tooltip label="大小" align="center" prop="fileSize" />
        <el-table-column resizable show-overflow-tooltip label="类型" align="center" prop="fileType" />
        <el-table-column resizable show-overflow-tooltip label="备注" align="center" prop="remark" />
        <el-table-column resizable label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button size="mini" type="text" @click="handleFileDelete(scope.row)" v-hasPermi="['train:FileFolder:edit']">删除</el-button>&nbsp;&nbsp;
            <el-button size="mini" type="text" v-if="scope.row.fileType == 'pdf' " @click="filePreview(scope.row.path)">预览</el-button>&nbsp;&nbsp;
            <el-link :href="scope.row.path" target="_blank">下载</el-link>
          </template>
        </el-table-column>
      </el-table>
      <pagination v-show="fileInfoTotal > 0" :total="fileInfoTotal" :page.sync="fileInfoQueryParams.pageNum"
        :limit.sync="fileInfoQueryParams.pageSize" @pagination="getList" />
    </el-dialog>
  </div>
</template>

<script src="./index.js"></script>
